﻿Imports System.Text

<DebuggerDisplay("{ToString()}")> _
Public Class Production
    Private m_sequence As Sequence
    Private m_nonTerminal As NonTerminal

    Public ReadOnly Property Sequence() As Sequence
        Get
            Return m_sequence
        End Get
    End Property

    Public ReadOnly Property NonTerminal() As NonTerminal
        Get
            Return m_nonTerminal
        End Get
    End Property

    Private m_index As Integer
    Friend Property Index() As Integer
        Get
            Return m_index
        End Get
        Set(ByVal value As Integer)
            m_index = value
        End Set
    End Property

    Public Sub New(ByVal seq As Sequence, ByVal production As NonTerminal)
        m_sequence = seq
        m_nonTerminal = production
    End Sub

    Public Overrides Function ToString() As String
        Dim builder As New StringBuilder
        With builder
            .Append(m_nonTerminal.ToString)
            .Append(" -> ")

            For Each symbol In Sequence
                .Append(symbol.ToString)
                .Append(" "c)
            Next
        End With

        Return builder.ToString
    End Function

    Private m_semanticRule As SemanticRule
    Public Property SemanticRule() As SemanticRule
        Get
            Return m_semanticRule
        End Get
        Set(ByVal value As SemanticRule)
            m_semanticRule = value
        End Set
    End Property
End Class